iOS Recipes (for Dee Robinson) by Matt Drance & Paul Warren
Author:Matt Drance & Paul Warren
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
ISBN: 978-1-934356-74-6
Publisher: The Pragmatic Bookshelf, LLC (291020)
* * *
Figure 23. Table view border shadows
Once again weâre inserting subviews to represent the shadows. Why wouldnât we just set the shadows as part of the standard table header and footer? Well, first of all, doing this would affect the tableâs content size. If we set the bottom shadow as the table footer, for example, the table would include room at the bottom for the content shadow so that it was always visible. That isnât what we want: we want the shadows to have no effect on the actual content size and to be visible only when the respective top or bottom ends of the content are exposed. Second, we want this class to support custom headers and footers without affecting their layout or behavior. Using subviews that are independent of the other content gives us the greatest flexibility and safety.
We start with a common initializer that is called whether the table is created in code or in Interface Builder. This âcommonInit method installs the four shadow views and performs some additional initialization.
ShadowedTables/Classes/PRPShadowedTableView.m
- (void)commonInit {
[self installShadows];
}
The previously shown screenshot has a table view that doesnât fill the screen, making the bottom two shadows always visible. In the screenshot, the table is also pulled down past the top of its content, revealing the two top shadows as well. This shadow placement creates an appearance that resembles the Clock app.
The âinstallShadows method invoked by âcommonInit initializes the four shadow views to use one of two shadow images. Both images are 1 pixel wide and safely stretchable to the left or right without any modifications. Each shadow view is then set up by the âinstallShadow: method for use in our table view. This step makes the shadows adaptable to any screenâiPhone, iPad, or whatever else comes along in the future.
ShadowedTables/Classes/PRPShadowedTableView.m
UIImage *upShadow = [UIImage imageNamed:@"shadowUp.png"];
UIImage *downShadow = [UIImage imageNamed:@"shadowDown.png"];
ShadowedTables/Classes/PRPShadowedTableView.m
- (void)installShadow:(UIImageView *)shadowView {
shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
CGRect contentFrame = shadowView.frame;
contentFrame.size.width = self.frame.size.width;
shadowView.frame = contentFrame;
[self repositionShadow:shadowView];
}
Now that the shadow subviews are installed, we can work on positioning them. The easiest shadow to manage is the shadow above the top of the tableâs content. This shadow should freely move with the rest of the content but stay above the top while not actually affecting the content size. We accomplish this by setting a negative Y origin on the shadow. Since this never changes, we need to do it only once, so itâs done early on from âinstallShadows.
ShadowedTables/Classes/PRPShadowedTableView.m
if (contentTopShadow == nil) {
contentTopShadow = [[UIImageView alloc] initWithImage:upShadow];
[self installShadow:contentTopShadow];
CGRect topShadowFrame = contentTopShadow.frame;
topShadowFrame.origin.y = -topShadowFrame.size.height;
contentTopShadow.frame = topShadowFrame;
}
The fixed shadows at the top and bottom of the table view require some more work. When the user scrolls a scroll view or table view, all of the subviews move accordingly, unless we do something special in âlayoutSubviews. Our âlayoutSubviews implementation first passes the message on to super to preserve the default UITableView behavior and then sends âupdateShadows to adjust the other three shadow views as needed.
ShadowedTables/Classes/PRPShadowedTableView.m
- (void)layoutSubviews {
[super layoutSubviews];
[self updateShadows];
}
First we update the fixed shadow at the top of the table. Because this subview
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7693)
Robo-Advisor with Python by Aki Ranin(7591)
Offensive Shellcode from Scratch by Rishalin Pillay(6087)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(4986)
Ego Is the Enemy by Ryan Holiday(4947)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4437)
Python for ArcGIS Pro by Silas Toms Bill Parker(4167)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3866)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3598)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3284)
Speed Up Your Python with Rust by Maxwell Flitton(3230)
Liar's Poker by Michael Lewis(3218)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3190)
Extreme DAX by Michiel Rozema & Henk Vlootman(3169)
Agile Security Operations by Hinne Hettema(3121)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3108)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3081)
Cryptography Algorithms by Massimo Bertaccini(3001)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2981)
